<?php

/**
 * This is the model class for table "tbl_comment".
 *
 * The followings are the available columns in table 'tbl_comment':
 * @property integer $id
 * @property integer $user_id
 * @property integer $status
 * @property string $timepost
 * @property string $content
 * @property integer $job_id
 *
 * The followings are the available model relations:
 * @property Job $job
 * @property Users $user
 */
class Comment extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Comment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_comment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, status, timepost, content, job_id', 'required'),
			array('user_id, status, job_id', 'numerical', 'integerOnly'=>true),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'job' => array(self::BELONGS_TO, 'Job', 'job_id'),
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
		);
	}
	protected function beforeValidate()
	{
		//parent::beforeValidate();
	
		if($this->isNewRecord)
		{
			// set the create date, last updated date and the user doing the creating
			$this->timepost = new CDbExpression('NOW()');
			$this->user_id = Yii::app()->user->id;
			$this->status =1;
		}
		return parent::beforeValidate();
		//return true;
	}
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'user_id' => 'User',
			'status' => 'Status',
			'timepost' => 'Timepost',
			'content' => 'Content',
			'job_id' => 'Job',
		);
	}
}